<?php
require_once './include/common.php';
$title="激活码发放平台";
include ('include/head.php');
echo '<div class="header"><ul class="nav nav-pills pull-right" role="tablist"><li role="presentation" class="active"><a href="index.php">返回首页</a></li></ul><h3 class="text-muted" align="left">激活码发放平台</h3></div><hr>'; 
echo '<h2><a href="/i.php?do=jh">平台邀请<body  background="http://zz.qqh.pw/1234.jpg"></body>码不定期更新</a></h2>'; 

		if($_GET['do'] == "jh"){
		if($_POST["submit"])

		{
			$lth=20;//激活码长度
			$chars = 'abcdefghijlkmnpqrstuvwxyz0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';          
			$chars = str_shuffle($chars); 
			
			for($i = $lth; $i--; ) {   
				$str .= substr($chars, mt_rand(0,strlen($chars)), 1);
			}
			
			$sql = "INSERT INTO `w_jh`(`key`) VALUES ('{$str}')";
			$d = $db->exec($sql);
		 if($d){
			 echo "生成成功！";
			}else{
			echo "生成失败！";
			}
		}
			echo '
			<div class="panel panel-default">
			<div class="panel-heading">
			<h3 class="panel-title">
			未使用的激活码
			</div>
			<div class="panel-body" align="left">';
		$pagesize = 10;
		$p1 = $_GET['p1']?$_GET['p1']:1;
		
		
		$offset1 = ($p1-1)*$pagesize;
		
		$sql = "SELECT `key` FROM `w_jh` WHERE zt='0' LIMIT  $offset1 , $pagesize";
		$do = $db->query($sql);
		$list = $do->fetchAll();
		echo '<ol style="padding:0 20px;">';
		foreach($list as $value){
			echo '<li>'.$value[key].'</li><hr>';
		}
		$z_sql = "SELECT `key` FROM `w_jh` WHERE zt='0'";
		$z_sth = $db->query($z_sql);
		$z_num = $z_sth->rowCount();
		echo '<font color="FF0000">还剩下'.$z_num.'条激活码未使用</font>
		</div>
		</div>';
		$pagenum=ceil($z_num/$pagesize);
		if ($pagenum > 1) {
			for($i=1;$i<=$pagenum;$i++) {
				if($i==$p1) {
					echo ' [',$i,']';
				} else {
					echo ' <a href="i.php?do=jh&p1=',$i,'">',$i,'</a>';
				}
			}
		}
		echo '<hr></ol>
<div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title">
		已使用的激活码
		</div>
		<div class="panel-body" align="left">';
		
//
		$p2 = $_GET['p2']?$_GET['p2']:1;
		$offset2 = ($p2-1)*$pagesize;
		$sql = "SELECT `key` FROM `w_jh` WHERE zt='1' LIMIT  $offset2 , $pagesize";
		$do = $db->query($sql);
		$list = $do->fetchAll();
		echo '<ol style="padding:0 20px;">';
		foreach($list as $value){
			echo '<li style="text-decoration:line-through; color: #C36">'.$value[key].'</li><hr>';
		}
		
		$z_sql = "SELECT `key` FROM `w_jh` WHERE zt='1'";
		$z_sth = $db->query($z_sql);
		$num = $z_sth->rowCount();
		echo '共使用了'.$num.'条激活码
		</div>
		</div>';
		
		$pagenum=ceil($num/$pagesize);

		//循环输出各页数目及连接
		if ($pagenum > 1) {
			for($i=1;$i<=$pagenum;$i++) {
				if($i==$p2) {
					echo ' [',$i,']';
				} else {
					echo ' <a href="i.php?do=jh&p2=',$i,'">',$i,'</a>';
				}
			}
		}
		echo '</ol>';
		
		}

include ('include/foot.php');

exit;